<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
use App\LayAdmin\Components\Template;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        //
    ];

    public function handle($request, Closure $next)
    {
        // 在控制器 __construct() 方法中无法使用 csrf_token() 获取。 只能加在这儿了
        Template::getInstance()->setCsrfToken(csrf_token());
        return parent::handle($request, $next);
    }
}
